using UnityEngine;
using UnityEngine.UI;

namespace RGuang.PlathformCtrl
{

    public class VictoryScreen : MonoBehaviour
    {
        [SerializeField] VoidEventChannel levelClearedEventChannel;
        [SerializeField] StringEventChannel clearTimeTextEventChannel;
        [SerializeField] Button btnNextLevel;
        [SerializeField] Text txtTime;

        private void OnEnable()
        {
            levelClearedEventChannel.AddListener(ShowUI);
            clearTimeTextEventChannel.AddListener(SetTimeText);
            btnNextLevel.onClick.AddListener(SceneLoader.LoadNextScene);
        }
        private void OnDisable()
        {
            levelClearedEventChannel.RemoveListener(ShowUI);
            clearTimeTextEventChannel.RemoveListener(SetTimeText);
            btnNextLevel.onClick.RemoveListener(SceneLoader.LoadNextScene);
        }
        void ShowUI()
        {
            GetComponent<Canvas>().enabled = true;
            GetComponent<Animator>().enabled = true;
            Cursor.lockState = CursorLockMode.None;
        }

        void SetTimeText(string data)
        {
            txtTime.text = data;
        }
    }
}

